/*
 * @Author: 李坤夏 likunxia@fpwis.com
 * @Date: 2023-03-10 08:54:40
 * @LastEditors: 李坤夏 likunxia@fpwis.com
 * @LastEditTime: 2023-03-18 10:10:10
 * @FilePath: /fp-cli/generators/app/index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const Generator = require("yeoman-generator");

module.exports = class extends Generator {
  // 重写父类方法
  // constructor(args, opts) {
  //   super(args, opts);
  // }

  //处理询问信息
  prompting() {
    return this.prompt([
      {
        type: "input",
        name: "appName",
        message: "请输入项目名称",
        default: this.appName,
      },
      {
        type: "list",
        name: "appMode",
        message: "请选择使用的模版:",
        choices: ["vue2", "vue3"],
      },
    ]).then((answers) => {
      this.answers = answers;
    });
  }

  //预设项目结构
  writing() {
    let srcDIr = this.sourceRoot();
    let destDir = this.destinationRoot();
    this.fs.copyTpl(srcDIr, destDir, this.answers);
  }

  // 安装依赖
  install() {
    this.env.options.nodePackageManagers = "npm";
  }

  //结束
  end() {
    this.log("项目创建成功");
  }
};
